home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / HippoDraw / HippoDrawSrc1.1 / Hippo.subproj / InspectData.m < prev    next >
Encoding:
Text File  |  1992-04-25  |  10.6 KB  |  393 lines

  1. /* InspectData.h        by Paul Kunz    December 1991
  2.  * Controls binding of the plot axes with the columns of the ntuple.
  3.  *
  4.  * Copyright (C)  1991  The Board of Trustees of
  5.  * The Leland Stanford Junior University.  All Rights Reserved.
  6.  */
  7.  
  8. #import "InspectData.h"
  9.  
  10. const char InspectData_h_rcsid[] = INSPECTDATA_H_ID;
  11. const char InspectData_m_rcsid[] = "$Id: InspectData.m,v 1.12 1992/04/05 18:19:44 pfkeb Rel $";
  12.  
  13. #import <appkit/Application.h>
  14. #import <appkit/Button.h>
  15. #import <appkit/ButtonCell.h>
  16. #import <appkit/Form.h>
  17. #import <appkit/Matrix.h>
  18. #import <appkit/NXBrowser.h>
  19. #import <appkit/NXBrowserCell.h>
  20.  
  21. #import "DrawDocument.h"
  22. #import "HDraw.h"
  23. #import "HGraphicView.h"
  24. #import "InspectTuple.h"
  25. #import "NewInspector.h"
  26. #import "Plot.h"
  27.  
  28. #import <strings.h>
  29.  
  30. #define LOW_RANGE 0
  31. #define HIGH_RANGE 1
  32. #define LOW_X 0
  33. #define LOW_Y 1
  34. #define HIGH_X 2
  35. #define HIGH_Y 3
  36. #define MAX_VALUE 0
  37. #define MIN_VALUE 1
  38. #define SUM_VALUE 2
  39. #define AX_X 0
  40. #define AX_Y 1
  41. #define AX_W 2
  42. #define AX_XE 2
  43. #define AX_YE 3
  44.  
  45. @implementation InspectData
  46.  
  47. - initInspFor:aDraw
  48. {    
  49.     int        i;
  50.     
  51.     [super initInspFor:aDraw];
  52.     
  53.     [NXApp loadNibSection:"InspectData.nib" owner:self
  54.            withNames:NO fromZone:[self zone]];
  55.     [theInspector addView:[contentBox contentView]
  56.                   withName:"Data Selection" withSupervisor:self];
  57.     currentDim = 1;
  58.     for ( i = 0; i < 4; i++ ) {
  59.         [[tpAxisForm cellAt:i :0] setEditable:NO];
  60.     }
  61.     return self;
  62. }
  63. - tupleAxisChanged:sender
  64. {
  65.     int        currentButton;
  66.     
  67.     currentButton = [tpAxisButtons selectedRow];
  68.  
  69.     if (graphtype == XYPLOT && currentButton >= 2)  currentButton += 1;
  70.     tpBrowserCells = [tpBrowser matrixInColumn:0];
  71.     [tpBrowserCells selectCellAt:tpAxisIndex[currentButton] :0 ];
  72.     [tpBrowserCells scrollCellToVisible:tpAxisIndex[currentButton]  :0];
  73.     return self;
  74. }
  75. - (int) currentTupleCol
  76. {
  77.     tpBrowserCells = [tpBrowser matrixInColumn:0];
  78.     return [tpBrowserCells selectedRow ];
  79. }
  80. - tupleSetAxisDataDim:sender
  81. {
  82.     int        currentTupleN, currentButton;
  83.     static int previousTupleN = -1, previousButton = -1;
  84.     drawtype_t          drawtype;
  85.  
  86.     tpBrowserCells = [tpBrowser matrixInColumn:0];
  87.     currentTupleN = [tpBrowserCells selectedRow ];
  88.     currentButton = [tpAxisButtons selectedRow];
  89.     [tpAxisForm setStringValue:
  90.     [[tpBrowserCells cellAt:currentTupleN :0] stringValue] at:currentButton];
  91.     switch( currentButton ) {
  92.     case AX_X:
  93.     [graphicView graphicsPerform:@selector(bindAxisX:)
  94.         with :(id)¤tTupleN andDraw:YES];
  95.         tpAxisIndex[0] = currentTupleN;
  96.     break;
  97.     case AX_Y:
  98.     [graphicView graphicsPerform:@selector(bindAxisY:)
  99.         with :(id)¤tTupleN andDraw:YES];
  100.         tpAxisIndex[1] = currentTupleN;
  101.     break;
  102.     case AX_W:
  103.     if (graphtype == XYPLOT) {
  104.         if (currentTupleN == previousTupleN && currentButton == previousButton) {
  105.             currentTupleN = -1;
  106.             drawtype = POINT;
  107.             [tpAxisForm setStringValue:"" at:AX_XE];
  108.         }
  109.         else drawtype = POINT + ERRBAR;
  110.  
  111.         [ graphicView graphicsPerform:@selector(setDrawType:)
  112.             with: (id)&drawtype andDraw:NO ];
  113.         [graphicView graphicsPerform:@selector(bindAxisXE:)
  114.             with :(id)¤tTupleN andDraw:YES];
  115.             tpAxisIndex[3] = currentTupleN;
  116.     } else {
  117.         if (currentTupleN == previousTupleN && currentButton == previousButton) 
  118.         {
  119.             currentTupleN = -1;
  120.             [tpAxisForm setStringValue:"" at:AX_W];
  121.         }
  122.         [graphicView graphicsPerform:@selector(bindAxisW:)
  123.             with :(id)¤tTupleN andDraw:YES];
  124.             tpAxisIndex[2] = currentTupleN;
  125.     }
  126.     previousTupleN = currentTupleN;
  127.     previousButton = currentButton;
  128.     break;
  129.     case AX_YE:
  130.     if (currentTupleN == previousTupleN && currentButton == previousButton) {
  131.         currentTupleN = -1;
  132.         drawtype = POINT;
  133.         [tpAxisForm setStringValue:"" at:AX_YE];
  134.     }
  135.     else drawtype = POINT + ERRBAR;
  136.  
  137.     [ graphicView graphicsPerform:@selector(setDrawType:)
  138.         with: (id)&drawtype andDraw:NO ];
  139.     [graphicView graphicsPerform:@selector(bindAxisYE:)
  140.         with :(id)¤tTupleN andDraw:YES];
  141.         tpAxisIndex[4] = currentTupleN;
  142.     previousTupleN = currentTupleN;
  143.     previousButton = currentButton;
  144.     break;
  145.     }
  146.     [[graphicView window] flushWindow];
  147.     return self;
  148. }
  149.  
  150.  /* Methods for updating Inspector */
  151. - updateView
  152. {
  153.     id        inspectTuple;
  154.     
  155.     if ( firstPlot ) {
  156.         [self setTuple:[firstPlot ntuple] ];
  157.     [self showBinding];
  158.     } else {
  159.         inspectTuple = [hDraw inspectTuple];
  160.     [self setTuple:[inspectTuple currentTuple]];
  161.     }
  162.     return self;
  163. }
  164. - setTuple:(ntuple) atuple
  165. {    
  166.         if ( selectedTuple == atuple ) return self;
  167.         selectedTuple = atuple;
  168.     if ( selectedTuple == NULL ) return self;
  169.         [tpBrowser loadColumnZero];
  170.     if ( firstPlot ) {
  171.         [firstPlot getDispType:&graphtype];
  172.         if ( graphtype == XYPLOT ) {
  173.             [tpAxisButtons selectCellAt:AX_Y :0];
  174.         }
  175.     }
  176.     [tpAxisForm setStringValue:h_getNtLabel(selectedTuple,0) at:AX_X];
  177.         return self;
  178. }
  179. - showBinding
  180.   /*
  181.    * called when we click on a different plot -
  182.    * load up the options panel to correspond to the selected plot
  183.    */
  184. {
  185.     int     row;
  186.     display adisplay = [firstPlot histDisplay];
  187.     
  188.     graphtype = h_getDispType(adisplay);
  189.     if (graphtype == HISTOGRAM)
  190.      currentDim = 1;
  191.     else
  192.      currentDim = 2;
  193.     
  194.   /*
  195.    * get the current bindings
  196.    */
  197.     tpAxisIndex[0] = h_getBinding(adisplay, XAXIS);
  198.     tpAxisIndex[1] = h_getBinding(adisplay, YAXIS);
  199.     tpAxisIndex[2] = h_getBinding(adisplay, WEIGHT);
  200.     tpAxisIndex[3] = h_getBinding(adisplay, XERROR);
  201.     tpAxisIndex[4] = h_getBinding(adisplay, YERROR);
  202.     
  203.  /*
  204.   * enable buttons and show titles
  205.   */
  206.     [self setButtonsAndTitles];
  207.  /*
  208.   * click on the X Axis button as a starting default
  209.   */
  210.     row = [ tpAxisButtons selectedRow ];
  211.     if ( row < 0 ) {
  212.     [tpAxisButtons selectCellAt:AX_X :0];
  213.     }
  214.     if ( ![[tpAxisButtons cellAt:row :0] isEnabled] ) {
  215.     [tpAxisButtons selectCellAt:AX_X :0];
  216.     }
  217.     
  218.     [self tupleAxisChanged:self];
  219.     return self;
  220. }
  221.  
  222. - setButtonsAndTitles
  223. {
  224.     int                 tupleN;
  225.  
  226.  /*
  227.   * clear all highlights 
  228.   */
  229.     tpBrowserCells = [tpBrowser matrixInColumn:0];
  230.  
  231.  /*
  232.   * enable X cell always 
  233.   */
  234.     [[tpAxisButtons cellAt:AX_X :0] setEnabled:YES];
  235.     [[tpAxisForm cellAt:AX_X :0] setTitle:"X Axis"];
  236.     tupleN = tpAxisIndex[0];
  237.     if ( selectedTuple && (tupleN >= 0) )
  238.     [tpAxisForm setStringValue:h_getNtLabel(selectedTuple, tupleN)
  239.                         at:AX_X];
  240.     else
  241.     [tpAxisForm setStringValue:"" at:AX_X];
  242.     [tpAxisForm drawCellAt:AX_X :0];
  243.  
  244.     switch (currentDim) {
  245.     case 1:
  246.     /*
  247.      * disable Y cell and remove form title 
  248.      */
  249.     [[tpAxisButtons cellAt:AX_Y :0] setEnabled:NO];
  250.     [[tpAxisForm cellAt:AX_Y :0] setTitle:"      "];
  251.     [tpAxisForm setStringValue:"" at:AX_Y];
  252.     [tpAxisForm drawCellAt:AX_Y :0];
  253.     /*
  254.      * enable weight cell and add title (if tuple has >1 dimension) 
  255.      */
  256.     if (selectedTuple) {
  257.         if (h_getNtDim(selectedTuple) > 1) {
  258.         [[tpAxisButtons cellAt:AX_W :0] setEnabled:YES];
  259.         [[tpAxisForm cellAt:AX_W :0] setTitle:"Weight"];
  260.         tupleN = tpAxisIndex[2];
  261.         if (tupleN >= 0)
  262.             [tpAxisForm 
  263.                 setStringValue:h_getNtLabel(selectedTuple, tupleN)
  264.                             at:AX_W];
  265.         else
  266.             [tpAxisForm setStringValue:"" at:AX_W];
  267.         [tpAxisForm drawCellAt:AX_W :0];
  268.  
  269.  
  270.         } else {
  271.         [[tpAxisButtons cellAt:AX_W :0] setEnabled:NO];
  272.         [[tpAxisForm cellAt:AX_W :0] setTitle:"      "];
  273.         [tpAxisForm setStringValue:"" at:AX_W];
  274.         [tpAxisForm drawCellAt:AX_W :0];
  275.         }
  276.     } else {
  277.         [[tpAxisButtons cellAt:AX_W :0] setEnabled:NO];
  278.         [[tpAxisForm cellAt:AX_W :0] setTitle:"      "];
  279.         [tpAxisForm setStringValue:"" at:AX_W];
  280.         [tpAxisForm drawCellAt:AX_W :0];
  281.     }
  282.         
  283.     /*
  284.      * disable Y error cell and remove title 
  285.      */
  286.     [[tpAxisButtons cellAt:AX_YE :0] setEnabled:NO];
  287.     [[tpAxisForm cellAt:AX_YE :0] setTitle:"       "];
  288.     [tpAxisForm setStringValue:"" at:AX_YE];
  289.     [tpAxisForm drawCellAt:AX_YE :0];
  290.     break;
  291.  
  292.     case 2:
  293.     /*
  294.      * enable Y cell and add form title 
  295.      */
  296.     [[tpAxisButtons cellAt:AX_Y :0] setEnabled:YES];
  297.     [[tpAxisForm cellAt:AX_Y :0] setTitle:"Y Axis"];
  298.     tupleN = tpAxisIndex[1];
  299.     if ( selectedTuple && (tupleN >= 0) )
  300.         [tpAxisForm setStringValue:h_getNtLabel(selectedTuple, tupleN)
  301.                          at:AX_Y];
  302.     else
  303.         [tpAxisForm setStringValue:"" at:AX_Y];
  304.     [tpAxisForm drawCellAt:AX_Y :0];
  305.  
  306.     /*
  307.      * for the XYPLOT, we enable X Errors and Y Errors 
  308.      */
  309.     if (graphtype == XYPLOT || graphtype == STRIPCHART) {
  310.         [[tpAxisButtons cellAt:AX_XE :0] setEnabled:YES];
  311.         [[tpAxisForm cellAt:AX_XE :0] setTitle:"X Error"];
  312.         tupleN = tpAxisIndex[3];
  313.         if ( selectedTuple && (tupleN >= 0) )
  314.         [tpAxisForm setStringValue:h_getNtLabel(selectedTuple, tupleN)
  315.                      at:AX_XE];
  316.         else
  317.         [tpAxisForm setStringValue:"" at:AX_XE];
  318.         [tpAxisForm drawCellAt:AX_XE :0];
  319.  
  320.  
  321.         [[tpAxisButtons cellAt:AX_YE :0] setEnabled:YES];
  322.         [[tpAxisForm cellAt:AX_YE :0] setTitle:"Y Error"];
  323.         tupleN = tpAxisIndex[4];
  324.         if ( selectedTuple && (tupleN >= 0) )
  325.         [tpAxisForm setStringValue:h_getNtLabel(selectedTuple, tupleN)
  326.                      at:AX_YE];
  327.         else
  328.         [tpAxisForm setStringValue:"" at:AX_YE];
  329.         [tpAxisForm drawCellAt:AX_YE :0];
  330.     }
  331.     /*
  332.      * for SCATTER plots we disable X Errors and Y Errors 
  333.      */
  334.     else if (graphtype == SCATTERPLOT) {
  335.         [[tpAxisButtons cellAt:AX_XE :0] setEnabled:NO];
  336.         [[tpAxisForm cellAt:AX_XE :0] setTitle:"       "];
  337.         [tpAxisForm setStringValue:"" at:AX_XE];
  338.         [tpAxisForm drawCellAt:AX_XE :0];
  339.  
  340.         [[tpAxisButtons cellAt:AX_YE :0] setEnabled:NO];
  341.         [[tpAxisForm cellAt:AX_YE :0] setTitle:"       "];
  342.         [tpAxisForm setStringValue:"" at:AX_YE];
  343.         [tpAxisForm drawCellAt:AX_YE :0];
  344.     }
  345.     /*
  346.      * for binned plots, we enable Weights and disable Y Errors 
  347.      */
  348.     else {
  349.         [[tpAxisButtons cellAt:AX_W :0] setEnabled:YES];
  350.         [[tpAxisForm cellAt:AX_W :0] setTitle:"Weight"];
  351.         tupleN = tpAxisIndex[2];
  352.         if ( selectedTuple && (tupleN >= 0) )
  353.         [tpAxisForm setStringValue:h_getNtLabel(selectedTuple, tupleN)
  354.                      at:AX_W];
  355.         else
  356.         [tpAxisForm setStringValue:"" at:AX_W];
  357.         [tpAxisForm drawCellAt:AX_W :0];
  358.  
  359.         [[tpAxisButtons cellAt:AX_YE :0] setEnabled:NO];
  360.         [[tpAxisForm cellAt:AX_YE :0] setTitle:"       "];
  361.         [tpAxisForm setStringValue:"" at:AX_YE];
  362.         [tpAxisForm drawCellAt:AX_YE :0];
  363.     }
  364.  
  365.     break;
  366.     default:
  367.     break;
  368.     }
  369.     return self;
  370. }
  371.     
  372. /* Delegate Methods for NXBrowsers */
  373. - (int) browser: sender fillMatrix: matrix inColumn: (int) column
  374. {
  375.     id                  aCell;
  376.     int                 i, nrows;
  377.  
  378.     if ( selectedTuple ) {
  379.         nrows = h_getNtDim(selectedTuple);
  380.     } else { 
  381.         nrows = 0;
  382.     }
  383.     for (i = 0; i < nrows; i++) {
  384.     [matrix insertRowAt:i];
  385.     aCell = [matrix cellAt:i :0];
  386.     [aCell setStringValue:h_getNtLabel(selectedTuple, i)];
  387.     [aCell setLeaf:YES];
  388.     [aCell setLoaded:YES];
  389.     }
  390.     return nrows;
  391. }
  392. @end
  393.